<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title></title>
</head>
<body>

<!--页面内容开始-->
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-3">
            <div class="ibox ">
                <div class="ibox-title">
                    <h5>部门</h5>
                </div>
                <div class="ibox-content">
                    <div id="budgetSum_deptTree"></div>
                </div>
            </div>
        </div>
        <div class="col-9">
            <div class="ibox ">
                <div class="ibox-title">
                    <h5>预算列表</h5>
                </div>
                <div class="ibox-content">
                    <div class="row">
                        <div class="col">
                            <div id="budgetSum_table_toolbar" style="margin: 0;">
                                <form role="form" id="budgetSum_form" class="form-inline">
                                    <div class="form-group m-r-xs">
                                        <label for="budgetSum_projectName" class="sr-only">预算项目</label>
                                        <input type="text" class="form-control" id="budgetSum_projectName"
                                               placeholder="预算项目">
                                    </div>
                                    <div class="form-group m-r-xs">
                                        <label for="budgetSum_cateName" class="sr-only">经济分类</label>
                                        <input type="text" class="form-control" id="budgetSum_cateName"
                                               placeholder="经济分类">
                                    </div>
                                    <div>
                                        <button class="btn btn-primary" type="button"
                                                onclick="budgetSumObj.refreshTable()">查询
                                        </button>
                                        <button class="btn btn-white" type="button"
                                                onclick="budgetSumObj.resetTable()">重置
                                        </button>
                                        <button class="btn btn-warning" type="button"
                                                onclick="budgetSumObj.expertTable()">
                                            <i class="fa fa-download"></i> 导出
                                        </button>
                                    </div>
                                </form>
                            </div>
                            <table id="budgetSum_table" class="table table-striped"></table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!--弹窗：预算附件-->
<div th:replace="web/budget/cur/budgetinfodetailfreezs-apply::budgetinfoetailfreezsApply"></div>
<script type="text/javascript">
    $().ready(function () {
        budgetSumObj.initDept();
        budgetSumObj.initTable();
        budgetSumObj.initFreezsTable();
        /*$('#budgetSum_freezsModal').on('show.bs.modal', function (event) {
            $('#budgetSum_freezs_table').bootstrapTable('refresh', {
                url: `/budget/his/budgetinfofreezs/freezsList/${budgetSumObj.sumId}`
            });
        })*/
    })
    var budgetSumObj = new Object({
        deptCode: "1",
        sumId: '1',
        refreshTable: function () {
            $('#budgetSum_table').bootstrapTable("refresh", {
                url: '/budget/tbudgetinfo/sumList',
                query: {
                    deptCode: budgetSumObj.deptCode,
                    projectName: $('#budgetSum_projectName').val(),
                    cateName: $('#budgetSum_cateName').val()
                }
            });
        },
        resetTable: function () {
            $('#budgetSum_form')[0].reset();
            $("input[type='hidden']").val("");
            $('#budgetSum_table').bootstrapTable("refresh");
        },
        expertTable: function () {
            $('#budgetSum_table').tableExport({
                type: 'excel',
                fileName: '预算导出'
            });
        },
        priBuildTreeData: function (datas) {
            for (i in datas) {
                datas[i].a_attr = {code: datas[i].code};
                if (datas[i].children != null) {
                    budgetSumObj.priBuildTreeData(datas[i].children);
                } else {
                    datas[i].type = 'leaf';
                }
            }
        },
        initDept: function () {
            $('#budgetSum_deptTree')
                .on('changed.jstree', function (e, data) {
                    if (data.action == 'select_node') {
                        if (!$('#budgetSum_deptTree').jstree('is_parent', data.node)) {
                            budgetSumObj.deptCode = data.node.a_attr.code;
                            budgetSumObj.refreshTable();
                        }
                    }

                })
                .jstree({
                    "core": {
                        "animation": 0,
                        "multiple": false,
                        data: function (node, cb) {
                            $.getJSON(`/budget/tbudgetinfo/deptTree`, {}, function (data) {
                                if (data.length > 0) {
                                    data[0].state = {opened: true};
                                    data[0].type = 'root';
                                }
                                budgetSumObj.priBuildTreeData(data);
                                cb(data)
                            });
                        }
                    },
                    "types": {
                        'default': {
                            'icon': 'fa fa-folder'
                        },
                        'root': {
                            'icon': 'fa fa-graduation-cap'
                        },
                        leaf: {
                            icon: 'fa fa-sitemap'
                        }
                    },
                    "plugins": [
                        "types"
                    ]
                });
        },
        initTable: function () {
            $('#budgetSum_table').bootstrapTable({
                toolbar: "budgetSum_table_toolbar",
                //showExport: true,
                exportDataType: "",
                exportTypes: ['excel'],
                exportOptions: {
                    fileName: function () {
                        return '预算导出'
                    }
                },
                formatNoMatches: function () {  //没有匹配的结果
                    return '暂无数据';
                },
                method: "post",
                columns: [{
                    title: '#',
                    align: 'center',
                    width: 50,
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                }, {
                    title: '预算部门',
                    field: 'deptName'
                }, {
                    title: '预算项目',
                    field: 'projectName'
                }, {
                    title: '经济分类',
                    field: 'cateName'
                }, {
                    title: '计划金额',
                    field: 'totalMoney',
                    formatter: function (value, row, index) {
                        return $.moneyFormat(value);
                    }
                }, {
                    title: '冻结金额',
                    field: 'freezsMoney',
                    formatter: function (value, row, index) {
                        let num = $.moneyFormat(value);
                        return `<a class="frzzse text-success" href="javascript:">${num}</a>`;
                    },
                    events: {
                        'click .frzzse': function (e, value, row, index) {
                            budgetinfoetailfreezsApplyObj.init(row.sumId);
                        }
                    }
                }, {
                    title: '支付金额',
                    field: 'useMoney',
                    formatter: function (value, row, index) {
                        return $.moneyFormat(value);
                    }
                }, {
                    title: '可用金额',
                    field: 'availableMoney',
                    formatter: function (value, row, index) {
                        return $.moneyFormat(value);
                    }
                }],
                responseHandler: function (res) {
                    return res.list;
                },
                onDblClickRow: function (row, $element, field) {

                }
            });
        },
        initFreezsTable: function () {
            $('#budgetSum_freezs_table').bootstrapTable({
                showExport: true,
                exportDataType: "",
                exportTypes: ['excel'],
                exportOptions: {
                    fileName: function () {
                        return '预算冻结导出'
                    }
                },
                formatNoMatches: function () {  //没有匹配的结果
                    return '暂无数据';
                },
                method: "post",
                columns: [{
                    title: '#',
                    align: 'center',
                    width: 50,
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                }, {
                    title: '预算部门',
                    field: 'deptName'
                }, {
                    title: '预算项目',
                    field: 'projectName'
                }, {
                    title: '经济分类',
                    field: 'cateName'
                }, {
                    title: '冻结金额',
                    field: 'money',
                    formatter: function (value, row, index) {
                        return $.moneyFormat(value);
                    }
                }, {
                    title: '单据号',
                    field: 'processCode'
                }],
                responseHandler: function (res) {
                    return res.data;
                }
            });
        }
    })

</script>
</body>
</html>